#include <iostream>

using namespace std;

int	main()
{
	int task;
	cin >> task;
	while (task--)
	{
		int e, f, c, count = 0;
		cin >> e >> f >> c;
		e += f;
		while (e >= c)
		{
			count += e / c;
			e = e % c + e / c;
		}
		cout << count << endl;
	}
	return 0;
}